import axios from 'axios'
import router from '@/router'
import { Toast } from 'mint-ui';
const state={
    phoneId:localStorage.phoneId,
    token:localStorage.token
}
const mutations={
    CHANGE_PHONE_ID(state,{phoneId,token}){
        state.phoneId=localStorage.phoneId=phoneId
        state.token=localStorage.token=token
    },
    DELETE_PHONE_ID(state){
        localStorage.clear()
        state.phoneId=state.token=null
        Toast('账号失效,请重新登陆');
    }
}
const actions={
    denglu({dispatch,commit},params){
        return axios.post("/login",params)
            .then(res=>{
                if(res.ok===1){
                    Toast('登陆成功');
                    commit('CHANGE_PHONE_ID',res)
                    router.push('/my')
                    console.log(res)
                }else{
                    Toast(res.msg);
                }
            })
    }
}
export default {
    state,
    mutations,
    actions
}